<?php

if (!$usr->checkPermission('mod_dates_tables','u'))
{
    print "<b>Sie haben nicht die entsprechenden Rechte, um die Tabellen einzurichten!</b>";
    exit;
}

if ($env->param('createTables')){
 if ($env->param('banner')){
   print "Erzeuge Termine<br>";
   $udba->query("Drop table if exists ".$tableforwarder."_mod_banner_customer;");
   $udba->query("create table ".$tableforwarder."_mod_banner_customer (".
        "id int unsigned not NULL auto_increment, ".
        "name varchar(255), descr text, ".
        "primary key(id));");
   $udba->query("Drop table if exists ".$tableforwarder."_mod_banner_banner;");
   $udba->query("create table ".$tableforwarder."_mod_banner_banner (".
        "id int unsigned not NULL auto_increment,".
        "cust_id int, size smallint unsigned not null, alttext varchar(255), " .
        "type varchar(100), url varchar(255) not null," .
        "primary key(id));");
   $udba->query("Drop table if exists ".$tableforwarder."_mod_banner_subscription;");
   $udba->query("create table ".$tableforwarder."_mod_banner_subscription (".
        "id int unsigned not NULL auto_increment,instance varchar(40) not null,".
        "banner_id int unsigned not null, year int unsigned not null,".
        "week smallint unsigned not null, primary key(id), index(instance));");
   // TODO Woche berechnen: getdate -> floor((yday - wday) / 7)
   $udba->query("Drop table if exists ".$tableforwarder."_mod_banner_conf;");
   $udba->query("create table ".$tableforwarder."_mod_banner_conf (".
        "id int unsigned not NULL auto_increment,instance varchar(40) not null,".
        "capacity int, primary key(id), index(instance));");
 }
} else {
?>
<?php echo $udba->getError() ?>
<form action="<?=$scriptname?>" method="GET">
                <input type="hidden" name="module" value="<?=$module?>">
                <input type="hidden" name="instance" value="<?=$instance?>">
                <input type="hidden" name="target" value="createTables.php">
                <input type="hidden" name="createTables" value="true">
        <input type="checkbox" value="on" name="banner">Banner<br>
        <input type="submit" class="button" value="einrichten">
</form>
<?php
}
?>